{{template "base.html" .}}

{{define "content"}}


<div style="padding: 10% 10%">
<!--操作按钮模板-->
<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-xs" lay-event="testRecord">考试记录</a>
    <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>
<div class="layui-inline">
    <input class="layui-input" name="id" id="input_Reload" autocomplete="off">
</div>
<button class="layui-btn" data-type="reload" id="btu_reload">搜索</button>
<!--操作按钮模板end-->
<div class="layui-btn-group demoTable">
    <a href="/teacher/stu_add"><button class="layui-btn" id="getadd">添加</button></a>
</div>
<table class="layui-table" lay-data="{ height: 'full-400', url: 'http://127.0.0.1:8080/teacher/stu_list', page:true, id:'idTest'}" lay-filter="demo" >
    <thead>
    <tr>
        <th lay-data="{field:'Number', sort: true, fixed: true}">学号</th>
        <th lay-data="{field:'Name',}">用户名</th>
        <th lay-data="{field:'Sex', sort: true}">性别</th>
        <th lay-data="{field:'Age', }">年龄</th>
        <th lay-data="{field:'Major',  sort: true}">专业</th>
        <th lay-data="{field:'Class',  sort: true}">班级</th>
        <th lay-data="{field:'StringTime', width:180, sort: true, fixed: 'right'}">创建时间</th>
        <th lay-data="{fixed: 'right', width:218, align:'center', toolbar: '#barDemo'}">操作</th>
    </tr>
    </thead>
</table>
</div>

<script>
    layui.use('table', function(){
        var table = layui.table;
        table.on('tool(demo)', function(obj){
            var data = obj.data;
            if(obj.event === 'del'){
                layer.confirm('真的删除该学生吗', function(index){
                    $.ajax({
                        url:'/teacher/stu/'+data.Id,
                        method:'DELETE',
                        data:data.field,
                        dataType:'JSON',
                        success:function(res){
                            if(res.code=='0'){
                                layer.msg("删除成功",{icon: 1, time: 1000},function(){}); //提交成功后刷新页面
                                obj.del();
                            }
                            else
                                layer.msg("删除失败",{icon: 1, time: 1000},function(){}); //提交成功后刷新页面
                        },
                    });
                    layer.close(index);
                });
            } else if(obj.event === 'edit'){
                location.href="/teacher/stu/"+data.Id
            } else if(obj.event === 'testRecord'){
                location.href="/teacher/stu_test/record/"+data.Id
            }
        });

        $("#btu_reload").on('click', function(){
            table.reload('idTest', {
                url: '/teacher/stu_list2?msg='+$('#input_Reload').val(),
                method:'get'
                ,where: {
                } //设定异步数据接口的额外参数
                //,height: 300
            });
        });
    });




</script>



{{end}}



